/**
 * 项目名称：tv   
 * 类名称：QuartzTools.java   
 * 类描述：   
 * 创建人：issac2009@vip.qq.com   
 * 创建时间：Jul 17, 20118:14:52 PM  
 * 修改人：Thinkpad User
 * 修改时间：Jul 17, 20118:14:52 PM   
 * 修改备注：   
 * @version 
 */
package com.tv.tools;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;

import com.tv.crawler.Crawler;
import com.tv.data.TVProcessor;
import com.tv.htmlparser.TVJsoupParser;


/**
 * @ClassName: QuartzTools.java
 * @Description: TODO
 * @author issac2009@vip.qq.com
 * @date Jul 17, 20118:14:52 PM
 */
public class QuartzTools {
	
	
	public void work(){
		
		System.out.println("**********");
		
		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("init.properties");   
		Properties p = new Properties();   
		try {   
		   p.load(inputStream);   
		} catch (IOException e1) {   
		   e1.printStackTrace();   
		}   
		
		//清除旧文件夹
		Crawler.deleteAllFiles(p.getProperty("website.src.page"));
		Crawler.deleteAllFiles(p.getProperty("website.src.file"));
		
		//开始爬取网页
		Crawler crawler = new Crawler();
		crawler.crawler(new String[]{"http://v.163.com/tvlist/lists.html"});
		
		//解析网页
		List<String> filesList = TVJsoupParser.traversal(p.getProperty("website.src.page"));
		TVJsoupParser parser = new TVJsoupParser();
		for (String file : filesList){
			parser.parseHtml(file);
		}
		
		//读入数据库
		/*
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationDemo.xml");
		TVProcessor  processor =  (TVProcessor)context.getBean("tvProcessor");
		processor.saveData();
		*/
		
		
	}
}
